

var express = require('express');
var app = express();
var config = require('./config/index');
var port = process.env.PORT || config.build.port;

const appData = require('./data.json');
const seller = appData.seller;
const goods = appData.goods;
const ratings = appData.ratings;
const apiRoutes = express.Router();

apiRoutes.get('/', function (req, res, next) {
    req.url = '/index.html';
    next();
});

app.use(apiRoutes);

app.get('/api/seller', (request, response) => {
    response.json({
        errno: 0,
        data: seller
    });
});
app.get('/api/goods', (request, response) => {
    response.json({
        errno: 0,
        data: goods
    });
});
app.get('/api/ratings', (request, response) => {
    response.json({
        errno: 0,
        data: ratings
    });
});

app.use('/api', apiRoutes);

app.use(express.static('./dist'));

module.exports = app.listen(port, function (err) {
    if (err) {
        console.log(err);
        return
    }
    console.log('Listening at http://localhost:' + port + '\n')
});